import time
import unittest
from selenium import webdriver
from unit_02.Page.Page2 import Page2
from selenium.webdriver.common.by import By
from unit_02.Tools.Tools import Tools
import logging


class TestCase(unittest.TestCase):
    def setUp(self) -> None:
        print('start case')
        # 初始化日志
        Tools().Log()
        self.driver = webdriver.Firefox()
        # 浏览器事件 窗口最大化
        self.driver.maximize_window()

    def tearDown(self) -> None:
        print('end case')
        time.sleep(5)
        # 浏览器事件 关闭驱动
        self.driver.quit()

    def test_01(self):
        logging.info('sraet test_01')
        po = Page2(self.driver)
        po.login_luoji()
        # 隐式等待
        self.driver.implicitly_wait(5)
        # 悬浮 我的酒仙
        po.xf_wdjx()
        time.sleep(2)
        # 2.点击我的订单
        po.click_order()
        time.sleep(3)
        # 窗口切换
        po.new_window()
        time.sleep(2)
        # 3.点击取消订单
        po.click_qxdd()
        time.sleep(2)
        # 断言 订单取消后不能恢复，是否继续取消订单？
        dy2 = self.driver.find_element(By.XPATH, '//*[@id="order-cancel-pop1"]/div[2]/div[1]').text
        print('断言2:', dy2)
        self.assertNotEqual('是否继续取消订单？ ',dy2)
        time.sleep(2)
        # 4.点击取消订单
        po.click_qd()
        time.sleep(2)
        logging.info('sraet test_01')

if __name__ == '__main__':
    unittest.main()
